import httpRequest from "@/utils/httpRequest";

const API = {
    //获取所有标签
    GETALLLABel_URL: "/label/get",
    //获取错题列表，查找错题
    GETMISTAKES_URL: "/question/list",
    //根据id删除错题
    DELETEMISTAKES_URL: "/question/status/0",
    //修改错题、新增错题
    MODIFYMISTAKE_URL: "/question",
    //上传图片
    PHOTO_URL: "/question/upload",
    //获取标签对应的错题数量
    LABELQUESTION_URL: "/question/labelCount",
    //获取学科对应的错题数量
    SUBJECTQUESTION_URL: "/question/subjectCount",
    //获取每月新增错题数
    MONTH_QUESTION_URL: "/question/createTimeCount",
    //获取优先级对应的错题数量
    PRIORITY_QUESTION_URL: "/question/priorityCount",
};
//查找错题
export const reqSearchMistakes = (questionTitle, current, pageSize, subjectName, labelName, startTime, endTime) => {
    const body = {questionTitle, current, pageSize, subjectName, labelName, startTime, endTime}
    return httpRequest.get(API.GETMISTAKES_URL, {params: body});
};
//获取所有标签
export const reqGetAllTag = () => {
    const userId = 1;
    const body = {userId};
    return httpRequest.get(API.GETALLLABel_URL, {params: body});
};
//获取错题列表
export const reqGetMistakes = () => {
    const current = 1;
    const pageSize = 5;
    const body = {current, pageSize};
    return httpRequest.get(API.GETMISTAKES_URL, {params: body});
};
//根据id删除错题
export const reqDeleteMistake = (questionId) => {
    const body = {questionId};
    return httpRequest.delete(API.DELETEMISTAKES_URL, {params: body});
};
//修改错题、新增错题
export const reqModifyMistake = (mistake) => {
    //修改错题
    if (mistake.id) {
        return httpRequest.put(API.MODIFYMISTAKE_URL, mistake);
    } else {
        //新增错题
        return httpRequest.post(API.MODIFYMISTAKE_URL, mistake)
    }

}
//上传图片
export const reqPhoto = (questionImage) => {
    const formData = new FormData();
    formData.append("questionImage", questionImage);
    // const body = {questionImage}
    httpRequest.post(API.PHOTO_URL, formData, {
        headers: {
            'Content-Type': 'multipart/form-data' // 设置请求头
        }
    });
};
//获取标签对应的错题数量
export const reqGetLabelQuestion = () => httpRequest.get(API.LABELQUESTION_URL);
//获取学科对应的错题数量
export const reqGetSubjectQuestion = () => httpRequest.get(API.SUBJECTQUESTION_URL);
//获取每月新增错题数
export const reqGetMonthQuestion = () => httpRequest.get(API.MONTH_QUESTION_URL);
//获取优先级对应的错题数量
export const reqGetPriorityQuestion = () => httpRequest.get(API.PRIORITY_QUESTION_URL);